package com.thirteen.app.controller;


import com.thirteen.app.dto.ExamRecordId;
import com.thirteen.app.dto.ExamRecordWithScoreResponse.PaperWithScoreDto;
import com.thirteen.app.service.PaperService;
import com.thirteen.app.utils.tools.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = {"考试记录"})
@RestController
@RequestMapping("/api/student/examRecord")
@CrossOrigin
public class ExamRecordController {

    @Resource
    private PaperService paperService;

    @ApiOperation("查看历史考试答案")
    @GetMapping("getPaperAndAnalysis")
    public CommonResult getPaperWithAnswer(ExamRecordId examRecordId) {

        PaperWithScoreDto paperWithScoreDto;

        Integer examRecordIdTmp = Integer.parseInt(examRecordId.getExamRecordId());

        try {
            paperWithScoreDto = paperService.queryPaperWithScore(examRecordIdTmp);
        } catch (Exception e) {
            return CommonResult.failed("查看试卷失败");
        }

        return CommonResult.success(paperWithScoreDto);
    }

}
